$(document).ready(function() {
	getEmployee();
	getReceiveCode();
});


function getEmployee() {
	$.getJSON('CS56002Srvl', {
		process_type: "getEmployee",
	}, function(result) {
		var options = '';
		options += '<option value="">-- เลือกพนักงาน  --</option>';
		for (var i = 0; i < result.values.length; i++) {

			options += '<option value="' + result.values[i] + '">' + result.messages[i] +  '</option>';
		}
		$("#InputEmployee").html(options); 
	});
}

function getReceiveCode() {
	$.getJSON('CS56002Srvl', {
		process_type: "getReceive",
	}, function(result) {
		var options = '';
		options += '<option value="">-- ทุกรหัส --</option>';
		for (var i = 0; i < result.values.length; i++) {

			options += '<option value="' + result.values[i] + '">' + result.messages[i] +  '</option>';
		}
		$("#InputReceiveCode").html(options); 
	});
}

function printReport() {
	
	var vaDateStart = $("#datetimepicker1").val();
	var vaDateEnd = $("#datetimepicker2").val();
	var vaReportType = $("#inputReportType").val();
	var vaInputEmployee = $("#InputEmployee").val();
	var vaInputReceiveCode = $("#InputReceiveCode").val();
	var vnUserId = $("#userId").val();
	var vnSiteId = $("#siteId").val();
	
	if(vaDateStart.trim().length == 0 || vaDateEnd.trim().length == 0 || vaInputEmployee.trim().length == 0 
			|| vaInputReceiveCode.trim().length == 0 || vaReportType.trim().length == 0)
	{
		$("#modal_content").html("กรุณากรอกข้อมูลให้ครบถ้วน");
		$("#warningModal").modal();
		return;
	}else{
		var url = reporturl;
		
		if(vaReportType == "before_receive"){
			url = url+"CS56002R.jsp";
			vaInputReceiveCode = "&receiveCode="+vaInputReceiveCode;
		} else if(vaReportType == "water_per_day"){
			url = url+"CS56003R.jsp";
			vaInputReceiveCode = "";
		} else if(vaReportType == "waste_pre_day"){
			url = url+"CS56004R.jsp";
			vaInputReceiveCode = "";
		} else if(vaReportType == "wastewater_pre_day"){
			url = url+"CS56005R.jsp";
			vaInputReceiveCode = "";
		} else if(vaReportType == "other_per_day"){
			url = url+"CS56006R.jsp";
			vaInputReceiveCode = "";
		} else if(vaReportType == "revenue_per_day"){
			url = url+"CS56007R.jsp";
			vaInputReceiveCode = "";
		}

		url = url+"?siteId="+vnSiteId+"&userId="+vnUserId+"&fromDate="+vaDateStart+"&toDate="+vaDateEnd+"&receiveEmployee="+vaInputEmployee+""+vaInputReceiveCode;
		window.open(url);
	}
	
}